
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-agentproduct-list" lay-filter="LAY-agentproduct-list"></table>
        </div>
    </div>
</div>
<script>
    layui.use(['index','table'], function () {
    var index = layer.load(2, { shade: false });
        var table = layui.table;
        //分类管理
        table.render({
            elem: '#LAY-agentproduct-list'
            , url: '@Html.Raw(Url.Action("List"))' //模拟接口
            ,method:'post'
            , page: true //开启分页
            , even: true
            , limit: 15
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'ProductId', width: 120, title: 'ID' }
                , { field: 'ProductName', title: '名称', minWidth: 100 }
                , { field: 'Price', title: '价格', width: 100 }
                , { field: 'Sku', title: 'SKU', width: 150 }
                , { field: 'Rate', edit: 'text',  title: '一级佣金(%)', width: 100 }
                , { field: 'ParentRate', edit: 'text',  title: '二级佣金(%)', width: 100 }
            ]]
            , text: { none: '一条数据也没有^_^' }
            , done: function () {
                layer.close(index);
            }
        });

        //监听搜索
        layui.form.on('submit(LAY-agentproduct-list)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: field
            }, 'data');
        });
        
        //监听单元格编辑
        table.on('edit(LAY-agentproduct-list)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.post('@Url.Action("Update")', { productId: data.ProductId, rate: obj.data.Rate, parentrate: obj.data.ParentRate});
        });

        var $ = layui.$, active = {}

        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
